{extend name="common/application" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/store_center.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
.install-box .pub-right .img-logo img {
    border-radius: 0;
}
</style>
{/block}
{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-bottom: 80px;">
        <div class="open-box">
            <div class="open-top">
                <p class="open-title">免费开店</p>
                <div class="open-prompt"><span class="icons icon-prompt"></span>重要提醒：根据法律规定，支付机构将根据身份信息的完善程度设定不同的余额支付额度，可能对店铺经营有影响（企业店铺不受影响），立即查看身份信息！
                </div>
                <p class="open-tip">申请开通店铺完全免费；一个身份证只能开一家店；开店之后店铺无法注销，申请到正式开通预计需要 5 个工作日。想了解更多开店攻略请看<a class="cl-b"
                                                                                                       href="javascript:;">开店规则必看</a>。
                </p>
                <div class="open-step">
                    <img src="_IMG_/open_step2.png">
                </div>
            </div>
            <div class="open-con">
                <div class="publist-box install-box">
                    <form>
                        <input type="hidden" id="span" name="label">
                        <input type="hidden" id="id" name="id" value="">
                        <div class="row">
                            <label class="pub-left">店铺类型:</label>
                            <div class="pub-right">
                                <p class="install"></p>
                            </div>
                        </div>
                        <div class="row">
							<input type="hidden" name="image" class="image">
                            <label class="pub-left">店铺招牌:</label>
                            <div class="pub-right">
                                <div class="img-logo" id="img-logo">
                                    <img src="">
                                </div>
                                <div class="upimg">
                                    <p>点击上传店铺招牌</p>
                                    <input type="file" name="img" id="upload-logo" onchange="previewImage(this,2)"
                                           accept="image/gif, image/jpeg, image/png" title="点击选择图片">
                                </div>
                                <div class="tip-box">
                                    <p>注：仅仅支持JPG、PNG、JPEG格式，文件小于4M</p>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">店铺名称:</label>
                            <div class="pub-right">
                                <input type="text" name="name" placeholder="请输入店铺名称" value="">
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">邮箱:</label>
                            <div class="pub-right">
                                <p class="revise-box"></p>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">手机号码:</label>
                            <div class="pub-right">
                                <!-- 修改跳转到个人中心-信息安全页面 -->
                                <p class="revise-box"></p>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">店铺标签:</label>
                            <div class="pub-right">
                                <p class="tag-box">
                                    <!--<span class="check-span">行政诉讼</span><span>专利代理</span><span>政策应用</span><span>设计开发</span><span>专利托管</span><span>专利评议</span><span>专利维权</span><span>设计开发</span>-->
                                </p>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">经验范围:</label>
                            <div class="pub-right">
                                <textarea name="scope" placeholder="输入店铺经营范围，不得多余200字" maxlength="200"></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left">服务宗旨:</label>
                            <div class="pub-right">
                                <textarea name="tenet" placeholder="输入店铺服务宗旨，不得多余200字" maxlength="200"></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <label class="pub-left"></label>
                            <div class="pub-right">
                                <a class="publish-btn" onclick="submit_btn()" href="javascript:;">提交</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script>
    $(function () {
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            var user_login = $.base64.decode(userinfo).split(",");
            var span = $("#span").val();
            $.ajax({
                type: "get",
                url: "{:url('api/shop/get_open6')}",
                data: {'uid': user_login[0]},
                dataType: 'jsonp',
                success: function (msg) {
                    if (msg.code == 200) {
                        $("#id").val(msg.data.id);
                        if (msg.data.shop_id == 1) {
                            $(".install").text('个人店铺');
                        } else {
                            $(".install").text('企业店铺');
                        }
						if (msg.data.image != null) {
                            $(".row").eq(1).find('img').attr('src', '/Images/Information/' + msg.data.image);
							$('.image').val(msg.data.image);
                        }else{
							$(".row").eq(1).find('img').attr('src', '/Images/Information/store.jpg');
						}
						$(".row").eq(2).find('input').val(msg.data.name);
                        $(".row").eq(6).find('textarea').val(msg.data.scope);
                        $(".row").eq(7).find('textarea').val(msg.data.tenet);
                        $(".revise-box").eq(0).html(msg.data.email + '<a href="/index.php/index/person/account.html">修改</a>');
                        $(".revise-box").eq(1).html(msg.data.phone + "<a href='/index.php/index/person/account.html'>修改</a>");

                        if (msg.data.label_shop.length > 0) {

                            for (var i = 0; i < msg.data.label_shop.length; i++) {
                                if ($.inArray(msg.data.label_shop[i].id + '', msg.data.label) != -1) {
                                    var html = '<span class="check-span" all="' + msg.data.label_shop[i].id + '">' + msg.data.label_shop[i].name + '</span>';

                                } else {
                                    html = '<span all="' + msg.data.label_shop[i].id + '">' + msg.data.label_shop[i].name + '</span>';
                                }
                                var arrs = new Array();
                                $("p.tag-box span[class='check-span']").each(function () {
                                    arrs.push($(this).attr('all'));
                                });
                                var all = arrs.join(",");
                                $("#span").val(all);
                                $('p.tag-box').append(html);
                            }

                            /*标签选择*/
                            $(document).ready(function () {
                                /*标签选择*/
                                $('p.tag-box span').on('click', function () {
                                    $(this).toggleClass('check-span');
                                    var arrs = new Array();
                                    $("p.tag-box span[class='check-span']").each(function () {
                                        arrs.push($(this).attr('all'));
                                    });
                                    var all = arrs.join(",");
                                    $("#span").val(all);
                                })
                            });
                        }
                    } else {
                        layer.msg(msg.message, {icon: 5, time: 5000});
                    }
                }
            })
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    })

    /* 图片上传*/
    function previewImage(obj) {
        var filepath = $(obj).val();
        fileObj = document.getElementById('upload-logo');
        value = window.URL.createObjectURL(fileObj.files[0]);
        file_size = obj.files[0].size;
        size = file_size / 1024;
        if (size > 1024 * 4) {
            $('#upload-logo').val("");
            layer.alert('上传图片不得大于4MB', {
                closeBtn: 0
            });
        } else {
            $('#img-logo img').attr("src", value)
        }
    }

    /*提交*/
    function submit_btn() {
        layer.confirm('<div class="submit-box"><p>' +
            '<img src="/static/web/images/right.png"></p><p>您的店铺已经创建成功，您可以在店铺中心的店铺资料设置中查看相关信息</p><div>', {
            closeBtn: 1,
            area: ['500px', '360px'],
            btn: ['立即前往', '取消'] //按钮
        }, function () {
            window.location.href = "{:url('index/store/install')}";
        }, function () {
            layer.closeAll();
        });
    }

    $(".publish-btn").click(function () {
        // var id = $("#id").val();
        // var image = $(".install").eq(1).attr('src');
        // var name = $(".install").eq(2).val();
        // var scope = $(".install").eq(5).val();
        // var tenet = $(".install").eq(6).val();

        //body.find("#user_id").val(user_uid);
        var formData = new FormData($('form')[0]);
        $.ajax({
            type: "post",
            url: "{:url('api/shop/store_open6')}",
            data: formData,
            dataType: 'json',
            success: function (msg) {
                if (msg.code == 200) {

                } else {
                    layer.msg(msg.message, {icon: 5, time: 5000});
                }
            },
            contentType: false, //必须false才会自动加上正确的Content-Type
            processData: false //必须false才会避开jQuery对 formdata 的默认处理
        })
    });
</script>
{/block}